{% extends "base.html" %}
{% load static %}
{% load crispy_forms_tags %}

{% block title %}
    Teacher Dashboard | {{ block.super }}
{% endblock title %}

{% block stylesheets %}
    {{ block.super }}
    <!-- Custom styles for this template -->
    <link href="{% static "laioffer/css/dashboard.css" %}" rel="stylesheet">
    <script type="text/javascript" src="{% static "codemirror/lib/codemirror.js" %}"></script>
    <link rel="stylesheet" href="{% static "codemirror/lib/codemirror.css" %}">
    <script type="text/javascript" src="{% static "codemirror/mode/python.js" %}"></script>
    <link rel="stylesheet" type="text/css" href="{% static "css/laioffer/inline_comment.css" %}" rel="stylesheet">
{% endblock stylesheets %}

{% block content %}

    {% if request.user.current_group == "Teacher" %}
        {% include "_teacher_sidebar.html" %}
    {% elif request.user.current_group == "Supervisor" %}
        {% include "_admin_sidebar.html" %}
    {% elif request.user.current_group == "Student" %}
        {% include "_student_sidebar.html" %}
    {% elif request.user.current_group == "Assistant" %}
        {% include "_ta_sidebar.html" %}
    {% endif %}

    <section id="main-content">
        <section class="wrapper">
            {% include "_message.html" %}
            <section class="panel">
                <div class="panel-heading">
                    {{ view.interview.title }}
                </div>
                <div class="panel-body">



                    {% for content in view.interview.contents.all %}

                        <form method="post"> {% csrf_token %}

                            <div class="form-group"
                                 data-content-id="{{ content.id }}"
                                 data-field-name="question">
                                <label for="id_question" class="control-label">Question</label>
                                <label class="hint"></label>
                                {% if view.is_student %}
                                    <pre class="prettyprint linenums"
                                         data-content-id="{{ content.id }}"
                                         data-field-name="question">{{ content.question }}</pre>
                                    <input type="hidden" name="question" value="{{ content.question }}">
                                {% else %}
                                    <textarea name="question" class="cm form-control">{{ content.question }}</textarea>
                                {% endif %}
                            </div>

                            <div class="form-group"
                                 data-content-id="{{ content.id }}"
                                 data-field-name="answer">
                                <div id="classname" style="display: none;">answers</div>
                                <div id="student" style="display: none;">True</div>
                                <div id="interview_id" style="display: none;">{{ view.interview.id }}</div>
                                <label for="id_answer" class="control-label">Answer</label>
                                <label class="hint"></label>
                                {% if view.is_student %}
                                    <textarea name="answer"
                                              class="cm form-control answers">{{ content.answer }}</textarea>
                                    <label class="hint"></label>
                                {% else %}
                                    <pre class="prettyprint linenums" data-content-id="{{ content.id }}" data-field-name="answer">{{ content.answer }}</pre>
                                {% endif %}
                            </div>

                            <div class="form-group"
                                 data-content-id="{{ content.id }}"
                                 data-field-name="comment">
                                <label for="id_comment" class="control-label">Comment</label>
                                <label class="hint"></label>
                                {% if view.is_student %}
                                        <pre class="prettyprint linenums" data-content-id="{{ content.id }}" data-field-name="comment">{{ content.comment }}</pre>
                                {% else %}
                                    <textarea name="comment" class="cm form-control">{{ content.comment }}</textarea>
                                {% endif %}
                            </div>

                        </form>
                        {% empty %}
                            {% if not view.is_student %}
                                pls add question
                            {% else %}
                                pls wait for teacher to create contents
                            {% endif %}
                    {% endfor %}

                    {% if not view.is_student %}
                        <h3>Add contents</h3>
                        <form method="post">
                            {% csrf_token %}
                            {{ view.content_form|crispy }}
                            <button class="btn btn-primary" type="submit">Create</button>
                            <a type="button" class="btn" href="javascript:history.back()">Cancel</a>
                        </form>
                    {% endif %}

                    {% if not view.is_student %}
                    <h3>Interview Summary</h3>
                    <form method="post">
                        {% csrf_token %}
                        {{ view.summary_form | crispy }}
                        <button class="btn btn-primary" type="submit">Update</button>
                            {% if view.task %}
                            <span id='task_status' data-task_status="{{ view.task.status }}"></span>
                            {% endif %}
                    </form>
                    {% else %}
                        {% if view.interview.summary %}
                            <h3>Interview Summary</h3>
                            <div class="well">
                                {{ view.interview.summary }}
                            </div>
                        {% endif %}
                    {% endif %}

                </div>
            </section>
        </section>
    </section>

{% endblock content %}

{% block javascripts %}
    {{ block.super }}
    <link href="{% static "code-prettify/prettify.css" %}" rel="stylesheet" type="text/css">
    <script src="{% static "code-prettify/prettify.js" %}" type="text/javascript"></script>
    <script type="text/javascript" src="{% static "laioffer/js/csrf.js" %}"></script>
    <script type="text/javascript" src="{% static "laioffer/js/rest/task.js" %}"></script>
    <script type="text/javascript" src="{% static "js/laioffer/interview.js" %}"></script>
    <script type="text/javascript">
      $.py = {};
      $.py.task_id = {{ view.interview.task.id }};
    </script>
    <script type="text/javascript" src="{% static "js/laioffer/task_btn.js" %}"></script>
{% endblock javascripts %}
